/*
 * Copyright (c) 2022-2024 Termony Co., Ltd. All rights reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "los_arch_cpu.h"
#include "rk_parameters.h"

UINT32 HalGetCpuNum(VOID)
{
    return RKCORE_NUM;
}

INT32 HalGetCpuId(UINTPTR affinity)
{
    INT32 cpuId;

    switch (affinity & 0xfff) {
        case CORE0_AFF: cpuId = 0; break;
        case CORE1_AFF: cpuId = 1; break;
        case CORE2_AFF: cpuId = 2; break;
        case CORE3_AFF: cpuId = 3; break;
#if defined(LOSCFG_SOC_RK3588)
        case CORE4_AFF: cpuId = 4; break;
        case CORE5_AFF: cpuId = 5; break;
        case CORE6_AFF: cpuId = 6; break;
        case CORE7_AFF: cpuId = 7; break;
#endif
        default : cpuId = -1; break;
    }

    return cpuId;
}

INTPTR HalGetAffinityFromCpuId(UINT32 cpuId)
{
    INTPTR affinity;

    switch (cpuId) {
        case 0: affinity = CORE0_AFF; break;
        case 1: affinity = CORE1_AFF; break;
        case 2: affinity = CORE2_AFF; break;
        case 3: affinity = CORE3_AFF; break;
#if defined(LOSCFG_SOC_RK3588)
        case 4: affinity = CORE4_AFF; break;
        case 5: affinity = CORE5_AFF; break;
        case 6: affinity = CORE6_AFF; break;
        case 7: affinity = CORE7_AFF; break;
#endif
        default: affinity = -1; break;
    }

    return affinity;
}